home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 887 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: A problem with fprintf
  5. Date: Tue, 09 Jan 96 20:51:03 GMT
  6. Organization: none
  7. Message-ID: <821220663snz@genesis.demon.co.uk>
  8. References: <4cs8ie$5ru@no-names.nerdc.ufl.edu> <4csdt4$mcn@castle.nando.net> <4cth3m$1c0@yarrow.wt.com.au>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4cth3m$1c0@yarrow.wt.com.au>
  15.            bvarley@yarrow.wt.com.au "bruce varley" writes:
  16.  
  17. >In a formal sense the debugger is right. 'src' is not the same as a
  18. >pointer to a string.
  19.  
  20. I can be formal if you like! :-)
  21.  
  22. In the original post src was stated to be a 'static array of characters'.
  23.  
  24. ISO 7.1.1
  25.  
  26. "A ``pointer to'' a string is a pointer to its initial (lowest addressed)
  27.  character."
  28.  
  29. ISO 6.2.1.1
  30.  
  31. "Except [[cases involving sizeof, & and string literal initialiers]] an
  32.  lvalue that has type ``array of type'' is converted to an expression that
  33.  has type ``pointer to type'' that points to the initial element of the
  34.  array object and is not an lvalue."
  35.  
  36. Put that together and given that the array src holds a string, then
  37. in the context of the example src evaluates to something that is formally
  38. a pointer to a string.
  39.  
  40. :-)
  41.  
  42. >&src[0] is closer to being formally right,
  43.  
  44. In the context that means exactly the same thing.
  45.  
  46. >if src is type char. If the debugger is REALLY finicky, it might go off
  47. >hunting for the null and spit the dummy if it doesn't find it.
  48.  
  49. Well, if the debugger can't handle broken code there's not much hope for it!
  50.  
  51. >One solution is to use pointers. char* is the right way to point to
  52. >the string to be output. 
  53.  
  54. Luckily src evaluates to a char *
  55.  
  56. >Not all compilers are this fussy.
  57.  
  58. And indeed no C compilers are this fussy.
  59.  
  60. -- 
  61. -----------------------------------------
  62. Lawrence Kirby | fred@genesis.demon.co.uk
  63. Wilts, England | 70734.126@compuserve.com
  64. -----------------------------------------
  65.